package Lee_code;

import java.util.Arrays;

public class Lee_718 {
    public int findLength(int[] nums1, int[] nums2) {
        int len1 = nums1.length;
        int len2 = nums2.length;

        String s1 = Arrays.stream(nums1).toArray().toString();
        String s2 = Arrays.stream(nums2).toArray().toString();

        return len1 > len2 ? count(s1, s2): count(s2, s1);
    }

    //s1是大数组
    private int count(String s1, String s2) {
        int max = 0;
        for (int i = 0; i < s2.length(); i++) {
            for (int j = i + 1; j <= s2.length(); j++) {
                String sub = s2.substring(i, j);
                if (s1.contains(sub))
                    max = Math.max(sub.length(), max);
            }
        }
        return max;
    }

    public static void main(String[] args) {
        int[] nums = {1,2,3};
        StringBuilder sb1 =new StringBuilder();
        StringBuilder sb2 =new StringBuilder();

        for (int i = 0; i < nums.length; i++) {
            sb1.append(nums[i]);
        }

        for (int i = 0; i < nums.length; i++) {
            sb2.append(nums[i]);
        }

        System.out.println(sb1.toString());

    }
}
